<?php
//==============================================
// 代码所有       PHPText.Net
// 代码作者       黄创钦,tine2cx@163.com
// 联系方式       QQ 233944397
// 本代码开源使用，可以随意修改传播，但请保留本版权
// 声明,谢谢合作！
//==============================================


	define("_NavLV_","ViewTopic");  //定义当前页面下拉菜单等级
	require "_Global.php";

	$B_ID=$_GET["bid"];
	$F_ID=$_GET["fid"];
	$T_ID=$_GET["tid"];

	if(CheckForumMode($B_ID,$F_ID) && !_UserLogin_)
	{
		ShowMegBox("这个主题只有注册用户可以查看！",'index.php','goto');
	}

	//统计浏览数
	$TopicInfo = TextDB_SearchData("Topic_B".$B_ID."_F".$F_ID,"TEXTDB_HID",$T_ID);
	TextDB_ChangeData("Topic_B".$B_ID."_F".$F_ID,"TEXTDB_HID",$T_ID,"浏览数",$TopicInfo[0]["浏览数"]+1);

	//获取主题信息
	$TopicInfo       = TextDB_SearchData("Topic_B".$B_ID."_F".$F_ID,"TEXTDB_HID",$T_ID);
	$BoardID         = $B_ID;  //获取板块ID
	$ForumID         = $F_ID; //获取子板块ID
	$TopicID         = $T_ID; //获取主题ID
	$TopicTitle      = $TopicInfo[0]["主题"];
	$TopicView       = $TopicInfo[0]["浏览数"];
	$TopicReply      = $TopicInfo[0]["回复数"];
	$TopicContent    = $TopicInfo[0]["内容"];
	$TopicCreateIP   = ENIP($TopicInfo[0]["发表IP"]);
	$TopicCreateDate = date('Y-m-d H:i:s',$TopicInfo[0]["创建时间"]);

	if(_UserLogin_)
	{
		$ReplyTopicButtonSta = "";
		$BoardNew = "show";
	}
	else
	{
		$ReplyTopicButtonSta = "disabled='disabled'";
	}

	if($TopicInfo[$TopicID]["回复数"])
	{
		if(CheckTopicRoot($B_ID,$F_ID,$T_ID))
		{
			$TopicModeDisplay = "show";
			$RootModeDisplay  = "none";
		}

		if(CheckRoot($B_ID,$F_ID) || CheckBoardRoot($B_ID) || CheckForumAdmin() || CheckForumRoot())
		{
			$TopicModeDisplay = "show";
			$RootModeDisplay  = "show";
		}
	}
	else
	{
		if(CheckTopicRoot($B_ID,$F_ID,$T_ID) || CheckRoot($B_ID,$F_ID) || CheckBoardRoot($B_ID) || CheckForumAdmin() || CheckForumRoot())
		{
			$TopicModeDisplay = "show";
			$RootModeDisplay  = "show";
		}
	}

	$user = explode("",$TopicInfo[0]["SID修改人"]);
	if($user[0])
	{
		$TopicChangeInfoDisplay = "show";
		$TopicChangeMemberID    = $user[0];
		$TopicChangeMemberName  = $user[1];
		$TopicChangeMemberIP    = ENIP($TopicInfo[0]["修改IP"]);
		$TopicChangeDate        = date('Y-m-d H:i:s',$TopicInfo[0]["修改时间"]);
	}
	else
	{
		$TopicChangeMemberID    = "";
		$TopicChangeMemberName  = "";
		$TopicChangeMemberIP    = "";
		$TopicChangeDate        = "";
	}

	$user = explode("",$TopicInfo[0]["SID发表人"]);  //获取发表人信息
	$TopicMemberID   = $user[0];   //获取发表人ID
	$TopicMemberName = $user[1];   //获取发表人名称

	if(CheckOnline($user[1]))
	{
		$TopicMemberOnlineDisplay  = "show";
	}

	$user = TextDB_SearchData("Members","昵称",$user[1]);
	if($user)
	{
		$TopicMemberLevel = $user[0]["等级"];
		if(empty($user[0]["头像"]))
		{
			$TopicMemberIMG = _SkinPath_."/_Images/NOFace.bmp";
		}
		else
		{
			$TopicMemberIMG = $user[0]["头像"];
		}

		$Skins = TextDB_SearchData("Skins","目录名",_SkinName_);
			if(!$Skins)
			{
				$Skins = TextDB_SearchData("Skins","目录名",'Default');
			}
		$Jobs  = explode("",$Skins[0]["在线图标".$user[0]["权限"]]);
		$TopicMemberJobs     = $Jobs[0];
		$TopicMemberTopic    = $user[0]["发帖数"];
		$TopicMemberIntegral = $user[0]["积分"];
		$TopicMemberDate     = date('Y-m-d',$user[0]["注册日期"]);

		if(empty($user[0]["签名"]))
		{
			$TopicSignedContent = "";
		}
		else
		{
			$TopicSignedDisplay = "show";
			$TopicSignedContent = $user[0]["签名"];
		}
	}
	else
	{
		$TopicMemberLevel    = 0;
		$TopicMemberIMG      = _SkinPath_."/_Images/NOFace.bmp";

		$TopicMemberJobs     = "游客";
		$TopicMemberTopic    = 0;
		$TopicMemberIntegral = 0;
		$TopicMemberDate     = 0000-00-00;

		$TopicSignedContent = "";
	}

	if(isset($_GET['PageFT_SN']))
	{
		$NowPage = $_GET['PageFT_SN']-1;
	}
	else
	{
		$NowPage = 0;
	}

	$ReplyInfo = TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID,NULL,NULL,'asc',NULL,($NowPage*5),5);  //获取回复信息
	$InfoMax   = TextDB_DataRows(TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID));
	if($ReplyInfo)
	{
		foreach($ReplyInfo as $K=>$R)
		{
			$R_ID                     = $R[0];
			$Replys[$K]["ReplyID"]    = $R_ID;
			$Replys[$K]["ID"]         = ($NowPage*5)+($K+1);
			$Replys[$K]["Content"]    = $R["内容"];
			$Replys[$K]["CreateIP"]   = ENIP($R["答复IP"]);
			$Replys[$K]["CreateDate"] = date('Y-m-d H:i:s',$R["创建时间"]);

			//检测是否为最后一帖
			if($InfoMax==$ReplyID+1)
			{
				//最后一帖
				if(CheckReplyRoot($B_ID,$F_ID,$T_ID,$R_ID) || CheckRoot($B_ID,$F_ID) || CheckBoardRoot($B_ID) || CheckForumAdmin() || CheckForumRoot())
				{
					$Replys[$K]["ReplyModeDisplay"]     = "show";
					$Replys[$K]["ReplyRootModeDisplay"] = "show";
				}
			}
			else
			{  //不是最后一帖
				if(CheckReplyRoot($B_ID,$F_ID,$T_ID,$R_ID))
				{
					$Replys[$K]["ReplyModeDisplay"]     = "show";
				}

				if(CheckRoot($B_ID,$F_ID) || CheckBoardRoot($B_ID) || CheckForumAdmin() || CheckForumRoot())
				{
					$Replys[$K]["ReplyModeDisplay"]     = "show";
					$Replys[$K]["ReplyRootModeDisplay"] = "show";
				}
			}

			//获取修改人信息
			$user = explode("",$R["SID修改人"]);
			if($user[0])
			{
				$Replys[$K]["ChangeInfoDisplay"] = "show";
				$Replys[$K]["ChangeMemberID"]    = $user[0];
				$Replys[$K]["ChangeMemberName"]  = $user[1];
				$Replys[$K]["ChangeMemberIP"]    = ENIP($R["修改IP"]);
				$Replys[$K]["ChangeDate"]        = date('Y-m-d H:i:s',$R["修改时间"]);
			}
			else
			{
				$Replys[$K]["ChangeMemberID"]    = "";
				$Replys[$K]["ChangeMemberName"]  = "";
				$Replys[$K]["ChangeMemberIP"]    = "";
				$Replys[$K]["ChangeDate"]        = "";
			}

			//获取回复人信息
			$user = explode("",$R["SID答复人"]);  //获取答复人信息
			$Replys[$K]["MemberID"]    = $user[0];   //获取答复人ID
			$Replys[$K]["MemberName"]  = $user[1];   //获取答复人名称

			//检测回复人是否存在
			if(CheckOnline($user[1]))
			{
				$Replys[$K]["MemberOnlineDisplay"]  = "show";
			}

			//获取回复人头像信息
			$user = TextDB_SearchData("Members","昵称",$user[1]);
			if($user)
			{
				$Replys[$K]["MemberLevel"]   = $user[0]["等级"];
				if(empty($user[0]["头像"]))
				{
					$Replys[$K]["MemberIMG"] = _SkinPath_."/_Images/NOFace.bmp";
				}
				else
				{

					$Replys[$K]["MemberIMG"] = $user[0]["头像"];
				}

				$Skins = TextDB_SearchData("Skins","目录名",_SkinName_);
				if(!$Skins)
				{
					$Skins = TextDB_SearchData("Skins","目录名",'Default');
				}
				$Jobs  = explode("",$Skins[0]["在线图标".$user[0]["权限"]]);
				$Replys[$K]["MemberJobs"]     = $Jobs[0];
				$Replys[$K]["MemberTopic"]    = $user[0]["发帖数"];
				$Replys[$K]["MemberIntegral"] = $user[0]["积分"];
				$Replys[$K]["MemberDate"]     = date('Y-m-d',$user[0]["注册日期"]);

				if(empty($user[0]["签名"]))
				{
					$Replys[$K]["SignedContent"] = "";
				}
				else
				{
					$Replys[$K]["SignedDisplay"] = "show";
					$Replys[$K]["SignedContent"] = $user[0]["签名"];
				}
			}
			else
			{
				$Replys[$K]["MemberLevel"]   = 0;
				$Replys[$K]["MemberIMG"] = _SkinPath_."/_Images/NOFace.bmp";

				$Replys[$K]["MemberJobs"]     = "游客";
				$Replys[$K]["MemberTopic"]    = 0;
				$Replys[$K]["MemberIntegral"] = 0;
				$Replys[$K]["MemberDate"]     = 0000-00-00;

				$Replys[$K]["SignedContent"] = "";
			}
		}
		//设置分页信息
		$PagetFT = PageFT($InfoMax,5,5,"CHS",array("首页","前一页","后一页","尾页"),array('总共 ',' 条','页'));
	}

	_Header(_ForumTitle_);
	require GetMod('ViewTopic');
	_Footer();
?>